package com.tangyuan.dto;

import com.tangyuan.enums.ActionConstant;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class UserActionDto {
    private Long userId;
    private Long movieId;
    private Integer categoryId;
    private Float grade;
    private Float collection;
    private Float thump;

    public Float getGrade() {
        if(grade == null){
            return ActionConstant.DEFAULT_WEIGHT_F;
        }
        return defaultValue(grade);
    }

    public Float getCollection() {
        if(collection == null){
            return ActionConstant.DEFAULT_WEIGHT_F;
        }
        return defaultValue(collection);
    }

    public Float getThump() {
        if(thump == null){
            return ActionConstant.DEFAULT_WEIGHT_F;
        }
        return defaultValue(thump);
    }

    private float defaultValue(float value){
        if (value <= -1.0f) {
            return -1.0f;
        } else if (value >= 1.0f) {
            return 1.0f;
        }
        return ActionConstant.DEFAULT_WEIGHT_F;
    }

}
